package edu.csl.study.shardingsphere.health.controller;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import edu.csl.study.shardingsphere.health.entity.HealthLevel;
import edu.csl.study.shardingsphere.health.entity.User;
import edu.csl.study.shardingsphere.health.entity.User2;
import edu.csl.study.shardingsphere.health.service.IUser2Service;
import edu.csl.study.shardingsphere.health.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 自动生成代码
 * @since 2022-05-19
 */
@RestController
@RequestMapping("/health/user2")
public class User2Controller {
    @Autowired
    IUser2Service user2Service;

    @RequestMapping("/list")
    public List<User2> getUsers() throws SQLException {

       return user2Service.getUsers();
    }
    @RequestMapping("/insert")
    public String processUsers() throws SQLException {
        user2Service.processUsers();
        return "insert SUCCESS";
    }

    @RequestMapping("/delete")
    public String deleteList() throws SQLException {
        user2Service.deleteAll();
        return "delete SUCCESS";
    }
    @RequestMapping("/update")
    public String update() throws SQLException {

        //把名字为rhb的用户年龄更新为18，其他属性不变
        UpdateWrapper<User2> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("user_id",2l).set("user_Name", System.currentTimeMillis()+"");

        user2Service.update(updateWrapper);
        return "update SUCCESS";
    }


}
